package io.wilson.demo.controller;

import io.springframework.common.response.ServerResponse;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cache")
public class CacheController {
    @Resource
    private CacheManager cacheManager;

    @PostMapping
    @Cacheable(cacheNames = "default", key = "#p0")
    public ServerResponse<String> put(@RequestParam String key, @RequestParam String val) {
        System.err.println("key: " + key);
        return ServerResponse.success(val);
    }

    @GetMapping
    public ServerResponse<?> get(@RequestParam String key) {
        return ServerResponse.success(cacheManager.getCache("default").get(key));
    }
}
